package com.lzy.wzy.utils;

import com.lzy.wzy.aspect.Api;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class AnnotationUtils {
    public static Map<String, String> getAllHandler() throws ClassNotFoundException {
        Map<String, String> map = new ConcurrentHashMap<>();
        List<Class> list = ClassUtils.getAllClasses();
        list.forEach(aClass -> {
            List<Method> methodList = Arrays.asList(aClass.getMethods());
            methodList.forEach(aMethod ->{
                if (aMethod.getAnnotation(Api.class) != null){
                    String name = aMethod.getName();
                    String className = aMethod.getDeclaringClass().getName();
                    className = className.substring(className.lastIndexOf(".")+1);
                    map.put(aMethod.getAnnotation(Api.class).value(), className+"."+name);
                }
            });
        });
        return map;
    }
}
